import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Approval from '@/router/modules/approval'
import Attendance from '@/router/modules/attendance'
import Department from '@/router/modules/department'
import Employee from '@/router/modules/employee'
import Permission from '@/router/modules/permission'
import Role from '@/router/modules/role'
import Salary from '@/router/modules/salary'
import Social from '@/router/modules/social'
import Dashboard from '@/router/modules/dashboard'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  Dashboard,
  Department,
  Role,
  Employee,
  Permission,
  Attendance,
  Approval,
  Salary,
  Social,
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
